clear all,close all,clc


path_cleandata = "~/Dropbox/IT_Revolution/Replication_package/JPE submission/Clean_data/";
path_output = "~/Dropbox/IT_Revolution/Replication_package/JPE submission/Output/";

ict_emp = readtable(strcat(path_cleandata, "late_ict_emp.csv"));
first_row = zeros(1, width(ict_emp));
first_row_tab = array2table(first_row, 'VariableNames', ict_emp.Properties.VariableNames);
ict_emp = [first_row_tab; ict_emp];

ict_inc = readtable(strcat(path_cleandata, "late_ict_inc.csv"));
ict_inc = [first_row_tab; ict_inc];

ict_emp_group = readtable(strcat(path_cleandata, "late_ict_group_emp.csv"));
ict_emp_group = [first_row_tab; ict_emp_group];

ict_emp_dgroup = readtable(strcat(path_cleandata, "late_ict_dgroup_emp_base.csv"));
ict_emp_dgroup = [first_row_tab; ict_emp_dgroup];

manuf_emp = readtable(strcat(path_cleandata, "early_manuf_emp.csv"));
manuf_emp = [first_row_tab; manuf_emp];

manuf_wage = readtable(strcat(path_cleandata, "early_wage.csv"));
manuf_wage = manuf_wage([1, 11, 21, 27], :);
%nan_row = array2table(NaN(1, 3), 'VariableNames', manuf_wage.Properties.VariableNames);
%manuf_wage = [manuf_wage; nan_row];


manuf_emp_group = readtable(strcat(path_cleandata, "early_manuf_group_emp.csv"));
manuf_emp_group = [first_row_tab; manuf_emp_group];

manuf_emp_dgroup = readtable(strcat(path_cleandata, "early_manuf_dgroup_emp_base.csv"));
manuf_emp_dgroup = [first_row_tab; manuf_emp_dgroup];

rho=0.02;
kappa=1;

eta_0=0;
psi_0=0.4;
delta_0=1/36;
theta_0=3;
a=28;

lambda_0=fzero(@(x) (x-delta_0)*(x+rho)-psi_0*delta_0/(theta_0+eta_0),delta_0*2);
Dlog_A=((eta_0+(1-exp(-lambda_0*30))*theta_0*(psi_0/rho)/(theta_0+psi_0/rho))*(theta_0-1)/(theta_0+eta_0))^(-1)*0.0990;
sd_ratio=1;
DlogA_0=Dlog_A;

eta_1=1000;
psi_1=2;
delta_1=1/20;
theta_1=5;

eta_2=1;

for i=1:6

if i==1
eta=eta_0;psi=psi_0;delta=delta_0;theta=theta_0;
end
if i==2
eta=eta_1;psi=psi_0;delta=delta_0;theta=theta_0;
end
if i==3
eta=eta_0;psi=psi_1;delta=delta_0;theta=theta_0;
end
if i==4
eta=eta_0;psi=psi_0;delta=delta_1;theta=theta_0;
end
if i==5
eta=eta_0;psi=psi_0;delta=delta_0;theta=theta_1;
end
if i==6
eta=eta_2;psi=psi_0;delta=delta_0;theta=theta_0;
end

lambda=fzero(@(x) (x-delta)*(x+rho)-psi*delta/(theta+eta),delta*2);
if i>1
Dlog_A=DlogA_0*sd_ratio;
end
j=1;
for t=0:1:29
Dlog_w(i,j)=(1-(1-exp(-lambda*t))*(psi/rho)/(theta+psi/rho+eta))*(theta-1)/(theta+eta)*Dlog_A;

Dlog_x(i,j)=(eta+(1-exp(-lambda*t))*theta*(psi/rho)/(theta+psi/rho+eta))*(theta-1)/(theta+eta)*Dlog_A/kappa;

hat_omega_0=(psi/rho)/(theta+psi/rho+eta)*(theta-1)/(theta+eta)*Dlog_A;
Dlog_C_in(i,j)=-(hat_omega_0)^2*(exp(-lambda*t) -(theta+eta))^2;
Dlog_C_0(i,j)=-(hat_omega_0)^2*(exp(-lambda*t) +psi/(rho+lambda)*exp(-lambda*0))^2;
Dlog_C_10(i,j)=-(hat_omega_0)^2*(exp(-lambda*t) +psi/(rho+lambda)*exp(-lambda*10))^2;
Dlog_C_20(i,j)=-(hat_omega_0)^2*(exp(-lambda*t) +psi/(rho+lambda)*exp(-lambda*20))^2;
Dlog_C_30(i,j)=-(hat_omega_0)^2*(exp(-lambda*t) +psi/(rho+lambda)*exp(-lambda*30))^2;

if t<a
    Dlog_x_old(i,j)=eta*Dlog_w(i,j);
    Dlog_x_younger(i,j)=Dlog_x_old(i,j)+1/(1-exp(-delta*a))*(1-exp(-lambda*t))*(psi/rho)/(theta+psi/rho+eta)*(theta-1)*Dlog_A;
else
    Dlog_x_old(i,j)=eta*Dlog_w(i,j)+(1-exp(-lambda*(t-a)))*(psi/rho)/(theta+psi/rho+eta)*(theta-1)*Dlog_A;
    Dlog_x_younger(i,j)=Dlog_x_old(i,j)+1/(1-exp(-delta*a))*(exp(-lambda*(t-a))-exp(-lambda*t))*(psi/rho)/(theta+psi/rho+eta)*(theta-1)*Dlog_A;
end

    
j=j+1;
end
end

Dlog_x_cross=Dlog_x_younger-Dlog_x_old;

%%%%%%%%%%%%
% Figure 5 %
%%%%%%%%%%%%

figure(5)
subplot(4,2,1)
hold on
title('Baseline $(\eta=0)$','Fontsize',20,'Interpreter','Latex')
grid on
plot([1980,1990,2000,2010,2019],[0,Dlog_x(1,1),Dlog_x(1,10),Dlog_x(1,20),Dlog_x(1,30)],'s','MarkerEdgeColor',[1 0 0],'MarkerFaceColor',[1 0 0],'MarkerSize',7)
plot([1980,1990,2000,2010,2019],ict_emp.coef','o','MarkerEdgeColor',[0 0 0],'MarkerFaceColor',[0 0 0],'MarkerSize',5)
plot([[1980,1990,2000,2010,2019];[1980,1990,2000,2010,2019]],[ict_emp.dn'; ict_emp.up'],'k-s','LineWidth',0.75,'MarkerEdgeColor',[0 0 0],'MarkerFaceColor',[0 0 0],'MarkerSize',2)
xticks([1980,1990,2000,2010,2019])
xticklabels({'1980','1990','2000','2010','2019'})
ylim([-0.1,0.31])
xlim([1975,2025])
legend('Model','Data, ICT','Location','NorthWest')
ylabel('$\Delta\log(x_t)$','Fontsize',16,'Interpreter','Latex'); ax=gca; ax.XAxis.FontSize = 16; ax.YAxis.FontSize = 16;
xlabel('(A.1)')
hold off

subplot(4,2,2)
hold on
title('$\eta=\infty$','Fontsize',20,'Interpreter','Latex'); ax=gca; ax.XAxis.FontSize = 16; ax.YAxis.FontSize = 16; 
grid on
plot([1900,1910,1920,1930,1940],[0,Dlog_x(2,1),Dlog_x(2,10),Dlog_x(2,20),Dlog_x(2,30)],'s','MarkerEdgeColor',[1 0 0],'MarkerFaceColor',[1 0 0],'MarkerSize',7)
plot([1900,1910,1920,1930,1940],manuf_emp.coef','d','MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',5)
plot([[1900,1910,1920,1930,1940];[1900,1910,1920,1930,1940]],[manuf_emp.dn'; manuf_emp.up'],'Color', [0.6 0.6 0.6], 'Marker', 's','LineWidth',0.75,'MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',2)
xticks([1900,1910,1920,1930,1940])
xticklabels({'1900','1910','1920','1930','1940'})
ylim([-0.1,0.31])
xlim([1895,1945])
legend('Model','Data, Manuf.','Location','NorthWest')
ylabel('$\Delta\log(x_t)$','Fontsize',16,'Interpreter','Latex'); ax=gca; ax.XAxis.FontSize = 16; ax.YAxis.FontSize = 16; 
xlabel('(A.2)')
hold off

subplot(4,2,3)
hold on
grid on
plot([1980,1990,2000,2010,2019],[0,Dlog_w(1,1),Dlog_w(1,10),Dlog_w(1,20),Dlog_w(1,30)],'s','MarkerEdgeColor',[1 0 0],'MarkerFaceColor',[1 0 0],'MarkerSize',7)
plot([1980,1990,2000,2010,2019],ict_inc.coef','o','MarkerEdgeColor',[0 0 0],'MarkerFaceColor',[0 0 0],'MarkerSize',5)
plot([[1980,1990,2000,2010,2019];[1980,1990,2000,2010,2019]],[ict_inc.dn'; ict_inc.up'],'k-s','LineWidth',0.75,'MarkerEdgeColor',[0 0 0],'MarkerFaceColor',[0 0 0],'MarkerSize',2)
xticks([1980,1990,2000,2010,2019])
xticklabels({'1980','1990','2000','2010','2019'})
ylim([-0.07,0.07])
xlim([1975,2025])
ylabel('$\Delta\log(\omega_t)$','Fontsize',16,'Interpreter','Latex'); ax=gca; ax.XAxis.FontSize = 16; ax.YAxis.FontSize = 16;
xlabel('(B.1)')
hold off

subplot(4,2,4)
hold on
grid on
plot([1900,1910,1920,1930,1940],[0,Dlog_w(2,1),Dlog_w(2,10),Dlog_w(2,20),Dlog_w(2,30)],'s','MarkerEdgeColor',[1 0 0],'MarkerFaceColor',[1 0 0],'MarkerSize',7)
plot([1900,1910,1920,1930],manuf_wage.change_waged781_d780','d','MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',5)
xticks([1900,1910,1920,1930,1940])
xticklabels({'1900','1910','1920','1930','1940'})
ylim([-0.07,0.07])
xlim([1895,1945])
ylabel('$\Delta\log(\omega_t)$','Fontsize',16,'Interpreter','Latex'); ax=gca; ax.XAxis.FontSize = 16; ax.YAxis.FontSize = 16; 
xlabel('(B.2)')
hold off


subplot(4,2,5)
hold on
grid on
plot([1980,1990,2000,2010,2019],[0,Dlog_x_old(1,1),Dlog_x_old(1,10),Dlog_x_old(1,20),Dlog_x_old(1,30)],'s','MarkerEdgeColor',[1 0 0],'MarkerFaceColor',[1 0 0],'MarkerSize',7)
plot([1980,1990,2000,2010,2019],ict_emp_group.coef2','o','MarkerEdgeColor',[0 0 0],'MarkerFaceColor',[0 0 0],'MarkerSize',5)
plot([[1980,1990,2000,2010,2019];[1980,1990,2000,2010,2019]],[ict_emp_group.dn2'; ict_emp_group.up2'],'k-s','LineWidth',0.75,'MarkerEdgeColor',[0 0 0],'MarkerFaceColor',[0 0 0],'MarkerSize',2)
xticks([1980,1990,2000,2010,2019])
xticklabels({'1980','1990','2000','2010','2019'})
ylim([-0.1,0.31])
xlim([1975,2025])
ylabel('$\Delta\log(x_t^{older})$','Fontsize',16,'Interpreter','Latex'); ax=gca; ax.XAxis.FontSize = 16; ax.YAxis.FontSize = 16; 
xlabel('(C.1)')
hold off 

subplot(4,2,6)
hold on
grid on
plot([1900,1910,1920,1930,1940],[0,Dlog_x_old(2,1),Dlog_x_old(2,10),Dlog_x_old(2,20),Dlog_x_old(2,30)],'s','MarkerEdgeColor',[1 0 0],'MarkerFaceColor',[1 0 0],'MarkerSize',7)
plot([1900,1910,1920,1930,1940],manuf_emp_group.coef2','d','MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',5)
plot([[1900,1910,1920,1930,1940];[1900,1910,1920,1930,1940]],[manuf_emp_group.dn2'; manuf_emp_group.up2'],'Color', [0.6 0.6 0.6], 'Marker', 's','LineWidth',0.75,'MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',2)
xticks([1900,1910,1920,1930,1940])
xticklabels({'1900','1910','1920','1930','1940'})
ylim([-0.1,0.31])
xlim([1895,1945])
ylabel('$\Delta\log(x_t^{older})$','Fontsize',16,'Interpreter','Latex'); ax=gca; ax.XAxis.FontSize = 16; ax.YAxis.FontSize = 16;
xlabel('(C.2)')
hold off

subplot(4,2,7)
hold on
grid on
plot([1980,1990,2000,2010,2019],[0,Dlog_x_cross(1,1),Dlog_x_cross(1,10),Dlog_x_cross(1,20),Dlog_x_cross(1,30)],'s','MarkerEdgeColor',[1 0 0],'MarkerFaceColor',[1 0 0],'MarkerSize',7)
plot([1980,1990,2000,2010,2019],ict_emp_dgroup.coef','o','MarkerEdgeColor',[0 0 0],'MarkerFaceColor',[0 0 0],'MarkerSize',5)
plot([[1980,1990,2000,2010,2019];[1980,1990,2000,2010,2019]],[ict_emp_dgroup.dn'; ict_emp_dgroup.up'],'k-s','LineWidth',0.75,'MarkerEdgeColor',[0 0 0],'MarkerFaceColor',[0 0 0],'MarkerSize',2)
xticks([1980,1990,2000,2010,2019])
xticklabels({'1980','1990','2000','2010','2019'})
ylim([-0.1,0.31])
xlim([1975,2025])
ylabel('$\Delta\log(x_t^{younger}/x_t^{older})$','Fontsize',16,'Interpreter','Latex'); ax=gca; ax.XAxis.FontSize = 16; ax.YAxis.FontSize = 16; 
xlabel('(D.1)')
hold off

subplot(4,2,8)
hold on
grid on
plot([1900,1910,1920,1930,1940],[0,Dlog_x_cross(2,1),Dlog_x_cross(2,10),Dlog_x_cross(2,20),Dlog_x_cross(2,30)],'s','MarkerEdgeColor',[1 0 0],'MarkerFaceColor',[1 0 0],'MarkerSize',7)
plot([1900,1910,1920,1930,1940],manuf_emp_dgroup.coef','d','MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',5)
plot([[1900,1910,1920,1930,1940];[1900,1910,1920,1930,1940]],[manuf_emp_dgroup.dn'; manuf_emp_dgroup.up'],'Color', [0.6 0.6 0.6], 'Marker', 's','LineWidth',0.75,'MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',2)
xticks([1900,1910,1920,1930,1940])
xticklabels({'1900','1910','1920','1930','1940'})
ylim([-0.1,0.31])
xlim([1895,1945])
ylabel('$\Delta\log(x_t^{younger}/x_t^{older})$','Fontsize',16,'Interpreter','Latex'); ax=gca; ax.XAxis.FontSize = 16; ax.YAxis.FontSize = 16;        
xlabel('(D.2)')
hold off

set(gcf,'Position',[100 100 1000 1000])
saveas(gcf,[strcat(path_output,'Figure_5.png')])
saveas(gcf,[strcat(path_output,'Figure_5.eps')])

%%%%%%%%%%%%
% Figure 6 %
%%%%%%%%%%%%

figure(6)
subplot(4,3,1)
hold on
title(['$\psi=',num2str(psi_1),'$'],'Fontsize',20,'Interpreter','Latex')
grid on
plot([1900,1910,1920,1930,1940],[0,Dlog_x(3,1),Dlog_x(3,10),Dlog_x(3,20),Dlog_x(3,30)],'s','MarkerEdgeColor',[1 0 0],'MarkerFaceColor',[1 0 0],'MarkerSize',7)
plot([1900,1910,1920,1930,1940],manuf_emp.coef','d','MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',5)
plot([[1900,1910,1920,1930,1940];[1900,1910,1920,1930,1940]],[manuf_emp.dn'; manuf_emp.up'],'Color', [0.6 0.6 0.6], 'Marker', 's','LineWidth',0.75,'MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',2)
xticks([1900,1910,1920,1930,1940])
xticklabels({'1900','1910','1920','1930','1940'})
legend('Model','Data, Manuf.','Location','NorthWest')
ylim([-0.1,0.31])
xlim([1895,1945])
ylabel('$\Delta\log(x_t)$','Fontsize',16,'Interpreter','Latex'); ax=gca; ax.XAxis.FontSize = 16; ax.YAxis.FontSize = 16;
xlabel('(A.1)')
hold off

subplot(4,3,2)
hold on
title(['$\delta=1/',num2str(1/delta_1),'$'],'Fontsize',20,'Interpreter','Latex')
grid on
plot([1900,1910,1920,1930,1940],[0,Dlog_x(4,1),Dlog_x(4,10),Dlog_x(4,20),Dlog_x(4,30)],'s','MarkerEdgeColor',[1 0 0],'MarkerFaceColor',[1 0 0],'MarkerSize',7)
plot([1900,1910,1920,1930,1940],manuf_emp.coef','d','MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',5)
plot([[1900,1910,1920,1930,1940];[1900,1910,1920,1930,1940]],[manuf_emp.dn'; manuf_emp.up'],'Color', [0.6 0.6 0.6], 'Marker', 's','LineWidth',0.75,'MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',2)
xticks([1900,1910,1920,1930,1940])
xticklabels({'1900','1910','1920','1930','1940'})
ylim([-0.1,0.31])
xlim([1895,1945])
ylabel('$\Delta\log(x_t)$','Fontsize',16,'Interpreter','Latex'); ax=gca; ax.XAxis.FontSize = 16; ax.YAxis.FontSize = 16;
xlabel('(A.2)')
hold off

subplot(4,3,3)
hold on
title(['$\theta=',num2str(theta_1),'$'],'Fontsize',20,'Interpreter','Latex')
grid on
plot([1900,1910,1920,1930,1940],[0,Dlog_x(5,1),Dlog_x(5,10),Dlog_x(5,20),Dlog_x(5,30)],'s','MarkerEdgeColor',[1 0 0],'MarkerFaceColor',[1 0 0],'MarkerSize',7)
plot([1900,1910,1920,1930,1940],manuf_emp.coef','d','MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',5)
plot([[1900,1910,1920,1930,1940];[1900,1910,1920,1930,1940]],[manuf_emp.dn'; manuf_emp.up'],'Color', [0.6 0.6 0.6], 'Marker', 's','LineWidth',0.75,'MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',2)
xticks([1900,1910,1920,1930,1940])
xticklabels({'1900','1910','1920','1930','1940'})
ylim([-0.1,0.31])
xlim([1895,1945])
ylabel('$\Delta\log(x_t)$','Fontsize',16,'Interpreter','Latex'); ax=gca; ax.XAxis.FontSize = 16; ax.YAxis.FontSize = 16;
xlabel('(A.3)')
hold off


subplot(4,3,4)
hold on
grid on
plot([1900,1910,1920,1930,1940],[0,Dlog_w(3,1),Dlog_w(3,10),Dlog_w(3,20),Dlog_w(3,30)],'s','MarkerEdgeColor',[1 0 0],'MarkerFaceColor',[1 0 0],'MarkerSize',7)
plot([1900,1910,1920,1930],manuf_wage.change_waged781_d780','d','MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',5)
xticks([1900,1910,1920,1930,1940])
xticklabels({'1900','1910','1920','1930','1940'})
ylim([-0.07,0.07])
xlim([1895,1945])
ylabel('$\Delta\log(\omega_t)$','Fontsize',16,'Interpreter','Latex'); ax=gca; ax.XAxis.FontSize = 16; ax.YAxis.FontSize = 16;
xlabel('(B.1)')
hold off

subplot(4,3,5)
hold on
grid on
plot([1900,1910,1920,1930,1940],[0,Dlog_w(4,1),Dlog_w(4,10),Dlog_w(4,20),Dlog_w(4,30)],'s','MarkerEdgeColor',[1 0 0],'MarkerFaceColor',[1 0 0],'MarkerSize',7)
plot([1900,1910,1920,1930],manuf_wage.change_waged781_d780','d','MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',5)
xticks([1900,1910,1920,1930,1940])
xticklabels({'1900','1910','1920','1930','1940'})
ylim([-0.07,0.07])
xlim([1895,1945])
ylabel('$\Delta\log(\omega_t)$','Fontsize',16,'Interpreter','Latex'); ax=gca; ax.XAxis.FontSize = 16; ax.YAxis.FontSize = 16;
xlabel('(B.2)')
hold off

subplot(4,3,6)
hold on
grid on
plot([1900,1910,1920,1930,1940],[0,Dlog_w(5,1),Dlog_w(5,10),Dlog_w(5,20),Dlog_w(5,30)],'s','MarkerEdgeColor',[1 0 0],'MarkerFaceColor',[1 0 0],'MarkerSize',7)
plot([1900,1910,1920,1930],manuf_wage.change_waged781_d780','d','MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',5)
xticks([1900,1910,1920,1930,1940])
xticklabels({'1900','1910','1920','1930','1940'})
ylim([-0.07,0.07])
xlim([1895,1945])
ylabel('$\Delta\log(\omega_t)$','Fontsize',16,'Interpreter','Latex'); ax=gca; ax.XAxis.FontSize = 16; ax.YAxis.FontSize = 16;
xlabel('(B.3)')
hold off

subplot(4,3,7)
hold on
grid on
plot([1900,1910,1920,1930,1940],[0,Dlog_x_old(3,1),Dlog_x_old(3,10),Dlog_x_old(3,20),Dlog_x_old(3,30)],'s','MarkerEdgeColor',[1 0 0],'MarkerFaceColor',[1 0 0],'MarkerSize',7)
plot([1900,1910,1920,1930,1940],manuf_emp_group.coef2','d','MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',5)
plot([[1900,1910,1920,1930,1940];[1900,1910,1920,1930,1940]],[manuf_emp_group.dn2'; manuf_emp_group.up2'],'Color', [0.6 0.6 0.6], 'Marker', 's','LineWidth',0.75,'MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',2)
xticks([1900,1910,1920,1930,1940])
xticklabels({'1900','1910','1920','1930','1940'})
ylim([-0.1,0.31])
xlim([1895,1945])
ylabel('$\Delta\log(x_t^{older})$','Fontsize',16,'Interpreter','Latex'); ax=gca; ax.XAxis.FontSize = 16; ax.YAxis.FontSize = 16;
xlabel('(C.1)')
hold off

subplot(4,3,8)
hold on
grid on
plot([1900,1910,1920,1930,1940],[0,Dlog_x_old(4,1),Dlog_x_old(4,10),Dlog_x_old(4,20),Dlog_x_old(4,30)],'s','MarkerEdgeColor',[1 0 0],'MarkerFaceColor',[1 0 0],'MarkerSize',7)
plot([1900,1910,1920,1930,1940],manuf_emp_group.coef2','d','MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',5)
plot([[1900,1910,1920,1930,1940];[1900,1910,1920,1930,1940]],[manuf_emp_group.dn2'; manuf_emp_group.up2'],'Color', [0.6 0.6 0.6], 'Marker', 's','LineWidth',0.75,'MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',2)
xticks([1900,1910,1920,1930,1940])
xticklabels({'1900','1910','1920','1930','1940'})
ylim([-0.1,0.31])
xlim([1895,1945])
ylabel('$\Delta\log(x_t^{older})$','Fontsize',16,'Interpreter','Latex'); ax=gca; ax.XAxis.FontSize = 16; ax.YAxis.FontSize = 16;
xlabel('(C.2)')
hold off

subplot(4,3,9)
hold on
grid on
plot([1900,1910,1920,1930,1940],[0,Dlog_x_old(5,1),Dlog_x_old(5,10),Dlog_x_old(5,20),Dlog_x_old(5,30)],'s','MarkerEdgeColor',[1 0 0],'MarkerFaceColor',[1 0 0],'MarkerSize',7)
plot([1900,1910,1920,1930,1940],manuf_emp_group.coef2','d','MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',5)
plot([[1900,1910,1920,1930,1940];[1900,1910,1920,1930,1940]],[manuf_emp_group.dn2'; manuf_emp_group.up2'],'Color', [0.6 0.6 0.6], 'Marker', 's','LineWidth',0.75,'MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',2)
xticks([1900,1910,1920,1930,1940])
xticklabels({'1900','1910','1920','1930','1940'})
ylim([-0.1,0.31])
xlim([1895,1945])
ylabel('$\Delta\log(x_t^{older})$','Fontsize',16,'Interpreter','Latex'); ax=gca; ax.XAxis.FontSize = 16; ax.YAxis.FontSize = 16;
xlabel('(C.3)')
hold off

subplot(4,3,10)
hold on
grid on
plot([1900,1910,1920,1930,1940],[0,Dlog_x_cross(3,1),Dlog_x_cross(3,10),Dlog_x_cross(3,20),Dlog_x_cross(3,30)],'s','MarkerEdgeColor',[1 0 0],'MarkerFaceColor',[1 0 0],'MarkerSize',7)
plot([1900,1910,1920,1930,1940],manuf_emp_dgroup.coef','d','MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',5)
plot([[1900,1910,1920,1930,1940];[1900,1910,1920,1930,1940]],[manuf_emp_dgroup.dn'; manuf_emp_dgroup.up'],'Color', [0.6 0.6 0.6], 'Marker', 's','LineWidth',0.75,'MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',2)
xticks([1900,1910,1920,1930,1940])
xticklabels({'1900','1910','1920','1930','1940'})
ylim([-0.1,0.31])
xlim([1895,1945])
ylabel('$\Delta\log(x_t^{younger}/x_t^{older})$','Fontsize',16,'Interpreter','Latex'); ax=gca; ax.XAxis.FontSize = 16; ax.YAxis.FontSize = 16;        
xlabel('(D.1)')
hold off

subplot(4,3,11)
hold on
grid on
plot([1900,1910,1920,1930,1940],[0,Dlog_x_cross(4,1),Dlog_x_cross(4,10),Dlog_x_cross(4,20),Dlog_x_cross(4,30)],'s','MarkerEdgeColor',[1 0 0],'MarkerFaceColor',[1 0 0],'MarkerSize',7)
plot([1900,1910,1920,1930,1940],manuf_emp_dgroup.coef','d','MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',5)
plot([[1900,1910,1920,1930,1940];[1900,1910,1920,1930,1940]],[manuf_emp_dgroup.dn'; manuf_emp_dgroup.up'],'Color', [0.6 0.6 0.6], 'Marker', 's','LineWidth',0.75,'MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',2)
xticks([1900,1910,1920,1930,1940])
xticklabels({'1900','1910','1920','1930','1940'})
ylim([-0.1,0.31])
xlim([1895,1945])
ylabel('$\Delta\log(x_t^{younger}/x_t^{older})$','Fontsize',16,'Interpreter','Latex'); ax=gca; ax.XAxis.FontSize = 16; ax.YAxis.FontSize = 16;        
xlabel('(D.2)')
hold off

subplot(4,3,12)
hold on
grid on
plot([1900,1910,1920,1930,1940],[0,Dlog_x_cross(5,1),Dlog_x_cross(5,10),Dlog_x_cross(5,20),Dlog_x_cross(5,30)],'s','MarkerEdgeColor',[1 0 0],'MarkerFaceColor',[1 0 0],'MarkerSize',7)
plot([1900,1910,1920,1930,1940],manuf_emp_dgroup.coef','d','MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',5)
plot([[1900,1910,1920,1930,1940];[1900,1910,1920,1930,1940]],[manuf_emp_dgroup.dn'; manuf_emp_dgroup.up'],'Color', [0.6 0.6 0.6], 'Marker', 's','LineWidth',0.75,'MarkerEdgeColor',[0.6 0.6 0.6],'MarkerFaceColor',[0.6 0.6 0.6],'MarkerSize',2)
xticks([1900,1910,1920,1930,1940])
xticklabels({'1900','1910','1920','1930','1940'})
ylim([-0.1,0.31])
xlim([1895,1945])
ylabel('$\Delta\log(x_t^{younger}/x_t^{older})$','Fontsize',16,'Interpreter','Latex'); ax=gca; ax.XAxis.FontSize = 16; ax.YAxis.FontSize = 16;        
xlabel('(D.3)')
hold off

set(gcf,'Position',[100 100 1000 1000])
saveas(gcf,[strcat(path_output, 'Figure_6.png')])
saveas(gcf,[strcat(path_output, 'Figure_6.eps')])

%%%%%%%%%%%%
% Figure 7 %
%%%%%%%%%%%%

psi=psi_0;delta=delta_0;theta=theta_0;Dlog_A=DlogA_0;
eta=0:0.01:100;

for j=1:length(eta) 
lambda=fzero(@(x) (x-delta)*(x+rho)-psi*delta/(theta+eta(j)),delta*2);

hat_omega_0=((psi/rho)/(theta+psi/rho+eta(j))*(theta-1)/(theta+eta(j)))*Dlog_A;
second_order(j)=(rho/(2*lambda+rho)*(1+delta/(2*lambda+rho)+(2+psi/rho)*delta*psi/(rho+lambda)^2)-rho/(rho+lambda)*2*(theta+eta(j))+(theta+eta(j))^2)*hat_omega_0^2;

DCIR_x(j)=theta*psi/rho/(theta+eta(j)+psi/rho)*(delta/(delta+lambda))*(theta-1)/(theta+eta(j));

omega_x=1;
dW(j)=-second_order(j)+omega_x/(1+omega_x)*Dlog_A*(rho+delta)/rho;

t=0;
a=0;
Dlog_w_0(j)=(psi/rho)/(theta+psi/rho+eta(j))*(theta-1)/(theta+eta(j))*Dlog_A;
Dlog_x_old_0(j)=eta(j)*Dlog_w_0(j);
Dlog_x_young_0(j)=Dlog_x_old_0(j)+(psi/rho)/(theta+psi/rho+eta(j))*(theta-1)*Dlog_A;
end


figure(7)
grid on
hold on;
plot(eta,second_order/second_order(1),'k-')
plot(eta,DCIR_x,'b:',eta,Dlog_x_old_0./Dlog_x_young_0,'r--')
legend({'Welfare Loss from Transition','$DCIR(x)$','$\Delta\log(x_0^{older})/\Delta\log(x_0^{younger})$'},'Fontsize',14,'Interpreter','Latex','Location','NorthEast') 
xlabel('Short-run labor supply elasticity $\eta$','Fontsize',14,'Interpreter','Latex');
xlim([0,10])
ax=gca; ax.XAxis.FontSize = 16; ax.YAxis.FontSize = 16;
hold off;
saveas(gcf,[strcat(path_output,'Figure_7.png')])
saveas(gcf,[strcat(path_output,'Figure_7.eps')])